
#ifndef __TCP_CLIENT_H
#define __TCP_CLIENT_H

#include <vector>
#include <apr-1/apr.h>
#include <apr-1/apr_file_io.h>
#include <apr-1/apr_portable.h>
#include "../aprtools/APRBucketBrigade.h"
#include "netgeneral.h"

// Ten minutes.
#define CLIENT_SOCKET_TIMEOUT 600000

/** A basic TCP client class. This is the base class for all types of 
 * clients. The constructor connects and the destructor disconnects. */
class TCPClient
{
   public:
      TCPClient(const char *ihostname, int iportno, apr_pool_t *imp);
      ~TCPClient();
      apr_off_t SendBuffer(const char *buf, apr_off_t buflen);
      std::vector<char> *RecvBuffer(apr_off_t len);
      apr_off_t SendBucketBrigade(APRBucketBrigade *aprbb);
      std::vector<char> *SendAndRecvBuffer(const char *buf, apr_off_t sendlen, apr_off_t recvlen);
   protected:
      /** Pipe to the socket. */
      APRBucketBrigade *clientbb;
      /** Pointer to the open outgoing socket. */
      apr_socket_t *tsocket;
      /** Pointer to the socket address information of the endpoint. */
      apr_sockaddr_t *addrstruct;
      /** Memory pool for use for allocating bits and pieces. */
      apr_pool_t *mp;
};

#endif
